#include <cerrno>
#include <cstdio>
#include <iostream>
#include <fcntl.h>
#include <sys/socket.h>
#include <unistd.h>
using namespace std;
void SetNonBlock(int fd) {
    int n = fcntl(fd, F_GETFD, 0);
    if(n < 0) {
        perror("fcntl");
        return;
    }
    fcntl(fd, F_SETFD, n | O_NONBLOCK);
}
int main() {
    SetNonBlock(0);
    char buffer[1024];
    while (1) {
        int n = read(0, buffer, sizeof(buffer) - 1); // 将标准读入设置成
        if(n > 0) {
            buffer[n] = '\0';
            cout << buffer << endl;
        }else if(n < 0) {
            if(errno == EAGAIN || errno == EWOULDBLOCK) {
                cout << "数据还没好" << endl;
                sleep(1);
                continue;
            }else if(errno == EINTR) {
                continue;
            }else {

            }
        }else {
            break;
        }
    }
    return 0;
}